"use strict";
import * as React from 'react';
import { commonStyles } from "../assets/styles/common";
import Avatar from "./Avatar";
import MyText from "./MyText";
import { commentStyles } from "../assets/styles/guide";
import Line from "./Line";
import { SCREEN_WIDTH } from "../constant";
import { dynamicStyles } from "../assets/styles/community";
import Colors from "../assets/styles/Colors";
const { connect } = require('react-redux');
const { View, TouchableOpacity } = require('react-native');
class CommentItem extends React.Component {
    constructor() {
        super(...arguments);
        this.onPraisePress = () => {
            if (this.props.onPraisePress) {
                this.props.onPraisePress(this.props.item);
            }
        };
        this.onDeletePraisePress = () => {
            this.props.onDeletePress && this.props.onDeletePress(this.props.item);
        };
        this.getPraiseCount = () => {
            if (!this.props.item.praise)
                return 0;
            return this.props.item.praise.counts;
        };
        this.getPraiseFlag = () => {
            let flag = false;
            if (this.props.item.praise) {
                if (Array.isArray(this.props.item.praise.praiseDTOList)) {
                    this.props.item.praise.praiseDTOList.map((item) => {
                        if (Number(item.userId) === Number(this.props.auth.userInfo.id)) {
                            flag = true;
                        }
                    });
                }
            }
            return flag;
        };
    }
    render() {
        const { item } = this.props;
        return (<View style={[{ backgroundColor: '#fff' }, this.props.style]}>
                <View style={[commonStyles.listItem, commentStyles.item, commonStyles.relative]}>
                    <Avatar source={{ uri: item.user.avatar }}/>
                    <View style={[commonStyles.flexColumn, commentStyles.leftContent]}>
                        
                        <MyText numberOfLines={1} style={commentStyles.name}>{item.user.nickName}</MyText>
                        
                        <MyText numberOfLines={1} style={commentStyles.sub}>{item.user.company ? item.user.company.name : ''}</MyText>
                        
                        <MyText numberOfLines={1} style={commentStyles.time}>{item.created}</MyText>

                        
                        <MyText numberOfLines={0} style={commentStyles.content}>{item.content}</MyText>
                        <Line style={{ width: SCREEN_WIDTH - 60 }}/>

                        
                        
                        
                        <View style={[commonStyles.flexRow, { padding: 10, justifyContent: 'space-between', marginRight: 10 }]}>
                            <TouchableOpacity onPress={this.onPraisePress}>
                                <MyText numberOfLines={0} style={[this.getPraiseFlag() ? dynamicStyles.isLiked : null]}>{`${this.getPraiseCount()}赞`}</MyText>
                            </TouchableOpacity>
                            <TouchableOpacity onPress={this.onDeletePraisePress}>
                                <MyText color={Colors.Danger}>{this.props.item.user.id === this.props.auth.userInfo.id && '删除'}</MyText>
                            </TouchableOpacity>
                        </View>
                    </View>
                </View>
                <Line style={{ marginTop: -13 }}/>
            </View>);
    }
}
export default connect(({ auth }) => ({ auth }))(CommentItem);
